import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;

public class MyThreadPoll {
    List<Thread> list = new ArrayList<>();
    BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1000);
    public MyThreadPoll(int n){
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(()->{
               while(true){
                   Runnable task = null;
                   try {
                       task = queue.take();
                       task.run();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
            });
            t.start();
            list.add(t);
        }
    }
    public void schedule(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}
